<template>
  <div :id="id" :data="data" />
</template>

<script>
export default {
  name: 'BaseEchartsComponent',
  props: ['id', 'data', 'time'],
  data() {
    return {
      ChartLineGraph: null
    }
  },
  watch: {
    time() {
      this.drawLineGraph(this.id, this.data)
      deep:true
    },

    data: {
      handler(newvalue, oldvalue) {
        this.drawLineGraph(this.id, newvalue)
      }
    },
    deep: true
  },
  mounted() {
    this.drawLineGraph(this.id, this.data)
  },
  beforeDestroy() {
    if (this.ChartLineGraph) {
      this.ChartLineGraph.clear()
    }
  },
  methods: {
    drawLineGraph(id, data) {
      const _this = this
      const myChart = document.getElementById(id)
      this.ChartLineGraph = this.$echarts.init(myChart)
      this.ChartLineGraph.setOption(data)
      window.addEventListener('resize', function() {
        _this.ChartLineGraph.resize()
      })
    }
  }
}
</script>

<style scoped>

</style>
